"""cassoapi URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from rest_framework_jwt.views import obtain_jwt_token
from apps.users import views as userviews
from apps.goods import views as goodsviews
from apps.useropera import views as useroperaviews
from apps.shopcar import views as shopcarviews


# 需要配置media访问路径
from django.views.static import serve
from cassoapi.settings import MEDIA_ROOT


# 统一管理接口
from rest_framework import routers

router = routers.DefaultRouter()

# 用户注册接口  用户详情
router.register(r"api/user", userviews.UserViewset, basename="user")

# 添加当前用户收货地址/获取地址详细
router.register(
    r"api/useraddress", userviews.UserAddressViewset, basename="useraddress"
)

# logo
router.register(r"api/logos", userviews.LogoViewset, basename="logos")

# 用户订单CRUD
router.register(r"api/order", useroperaviews.OrderViewset, basename="order")

# 客服中心
router.register(
    r"api/servercenter", useroperaviews.ServerCenterViewset, basename="servercenter"
)

# 产品总目录
router.register(r"api/category", goodsviews.HuaweiCategoryViewset, basename="Category")
# 产品子目录
router.register(
    r"api/subcategory", goodsviews.HuaweiSubCateGoryViewset, basename="Subcategory"
)
# 商品列表
router.register(r"api/goods", goodsviews.HuaweiGoodsViewset, basename="Goods")

router.register(
    r"api/goodscontentimages",
    goodsviews.HuaweiGoodContentImageListViewset,
    basename="Goodscontentimages",
)
router.register(
    r"api/goodsdetialimages",
    goodsviews.HuaweiGoodsDetialImgListViewset,
    basename="Goodsdetialimages",
)
router.register(
    r"api/goodsdetialinfos",
    goodsviews.HuaweiGoodDetialInfosViewset,
    basename="Goodsdetialinfos",
)
# 用户收藏
router.register(r"api/fav", useroperaviews.FavoriteViewset, basename="userfav")

# 用户头像
router.register(r"api/avatar", userviews.UserAvatarViewset, basename="sueravatar")

# 用户购物车
router.register(r"api/shopcar", shopcarviews.ShopcarViewset, basename="shopcar")

# swagger
# from rest_framework.schemas import get_schema_view
# from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer

# schema_view = get_schema_view(
#     title="Users API", renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer]
# )

urlpatterns = [
    path("api/admin/", admin.site.urls),
    # swagger接口文档路由
    # path(r"api/docs/", schema_view, name="docs"),
    path("", include(router.urls)),
    # 测试阶段api页面的登录接口（测试页面右上角的login）
    # path(r"api-auth/", include("rest_framework.urls")),
    # path("adduseraddress/", userviews.AddUserAddressViewset),
    # 登入验证，只要用户名跟密码正确会自动生成token返回
    # media 访问路径配置
    path("api/media/<path:path>", serve, {"document_root": MEDIA_ROOT}),
    path("api/login/", obtain_jwt_token),  # 自动签发token
    path("api/wxlogin", userviews.wxlogin),
    # 添加数据的接口-- 添加数据后先注释掉，因为没有做数据重复添加的处理
    # path("api/addcategory/", goodsviews.addCategory),
    # path("api/addsubcategory/<int:pk>", goodsviews.addChildCategory),
]
